package logic

import (
	"context"
	"rubbish-cart/rpc/rubbish/model"

	"rubbish-cart/rpc/rubbish/internal/svc"
	"rubbish-cart/rpc/rubbish/rubbish"

	"github.com/tal-tech/go-zero/core/logx"
)

type UpdateCartRubbishLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateCartRubbishLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCartRubbishLogic {
	return &UpdateCartRubbishLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}


func (l *UpdateCartRubbishLogic) UpdateCartRubbish(in *rubbish.UpdateCartRubbishReq) (*rubbish.UpdateCartRubbishResp, error) {
	var ok = true
	err := l.svcCtx.Model.Update(model.Rubbish{
		Id:in.RubbishInfo.Id,
		CartId:        in.RubbishInfo.CartId,
		RubbishType:   in.RubbishInfo.TypeId,
		RubbishAmount: in.RubbishInfo.Num,
	})
	//res, err := l.svcCtx.Model.FindOneById(in.CartId, in.RubbishInfo.TypeId)
	//fmt.Println("---RPC UpdateCartRubbish() RES : ", res)
	//fmt.Println("---RPC UpdateCartRubbish() ERROR : ", err)
	if err != nil {
		ok = false
	}
	return &rubbish.UpdateCartRubbishResp{Ok: ok}, nil
}
